import PageTools from './PageTools'
import UploadExcel from './UploadExcel'
import * as myFilter from '@/filters'
import ImageUpload from './ImageUpload'

export default {
  install(Vue) {
    //   自定义指令 图片错误显示默认图片
    Vue.directive('imgerr', {
      inserted: function(el, binding) {
        // console.log(el, binding)
        // 没有src就用默认图片
        el.src = el.src || binding.value
        el.onerror = () => {
        //   console.log('出错了')
        //   出错了就用默认图片
          el.src = binding.value
        }
      }
    })
    // 工具条
    Vue.component('PageTools', PageTools)
    // 上传Excel
    Vue.component('UploadExcel', UploadExcel)
    // 图片上传
    Vue.component('ImageUpload', ImageUpload)
    // 过滤器
    Object.keys(myFilter).forEach(key => {
      Vue.filter(key, myFilter[key])
    })
  }
}
